Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add yaw recovery that uses only IMU and GPS data #13603

Closed
wants to merge 61 commits into from

Conversation

priseborough
Copy link
Contributor

@priseborough priseborough commented Feb 18, 2020

This PR implements a prototype multiple hypothesis estimation algorithm that enables recovery from an EKF3 navigation failure caused by a bad yaw estimate.

This is the culmination of algorithm development work that was first presented at the ArduPilot Un-Conference in 2018. See time 35:34 in the following presentation https://www.youtube.com/watch?v=XCl1Md-2Epc

In summary:

  • it uses up to 3% of an STM32-F4 per EKF core depending on how many yaw filters are used.
  • It implements a bank of up to eight 3-state EKF (Extended Kalman Filter) estimators, each starting with a different initial yaw. Simulation shows there is scope for reducing the number of filters down to a minimum of 3, but this needs to be evaluated using real data with vibration and GPS interference effects. Limited flight testing with 5 filters has been performed.
  • The EKF states are North,East Velocity and yaw angle.
  • A bank of up to eight AHRS algorithms using a simple complementary filter is used to provide an independent attitude reference for each EKF such that the IMU data can be rotated into a horizontal front, right reference frame with yaw rate. The AHRS calculations run from startup.
  • During fixed wing flight, the airspeed is used by the AHRS calculations to provide compensation for centripetal acceleration.
  • The output from each EKF is then combined using a GSF (Gaussian Sum Filter) which computes a weighting for each EKF.
  • The EKF and GSF calculations only run in flight.
  • The number of times the main EKF can reset yaw to this filter value is limited by parameter to 2 and is performed if the EKF is requested to check for a lane switch. This coordination between the external EKF failsafe logic, the yaw reset this Pr introduces and the lane switch decision needs to be imrpoved.

The Matlab derivation and scripts are available here: https://github.com/priseborough/3_state_filter.

The following SITL test results were obtained using the SITL ArduCopter simulation with the following parameter changes from the defaults:

EK2_ENABLE = 0
EK3_ENABLE = 1
AHRS_EKF_TYPE = 3
EKF_IMU_MASK = 1 (done to reduce log size and number of console messages during algorithm testing)

The SIM_Aircraft.cpp file was modified as shown below to induce over 90 degrees of initial heaidng error:

image

The following plot shows how the bank of 8 EKF filters and the weighted average generated by the Gaussian Sum Filter (GSF) converges within 2 seconds of the flyaway commencing. The reset of the main navigation filter yaw can be seen:

image

The following figure shows the weights calculated by the GSF and used to form the weighted average yaw output. It also shows the estimated yaw uncertainty (square root of the variance):

image

TODO

  • More flight testing. It has limited flight testing using a QuadPlane and Copter, but QuadPlane testing was for the yaw estimator only and did not test the failsafe and reset. Copter test video here: https://www.youtube.com/watch?v=3xW9hj-lxNU

Follow On Work

This work is best done in separate pull requests and includes:

  • Adding it to EKF2.
  • Potentially moving the EKFGSF_yaw class to a separate library with it's own sensor buffers.
  • Adding failsafe integration for vehicle classes other than Copter that wish to use it. This requires adding the call to AP_AHRS_NavEKF::check_lane_switch prior to enacting a loss of navigation failsafe response.

@priseborough
Copy link
Contributor Author

priseborough commented Feb 18, 2020

After discussions with Tridge, it makes sense for this to go into a separate library that can be used by both EKF2 and EKF3. The use by each estimator core should be controllable by a parameter enabling it to be set to off, ride-along, active (able to be used by resets) and any other use options.

@priseborough
Copy link
Contributor Author

priseborough commented Feb 22, 2020

The following graphs are from testing performed using a quadplane. This platform type enables both copter and fixed wing flight motion characteristics to be tested. For this test the number of filter banks was set to 5. A vertical takeoff was performed in QLOITER followed by a transition to horizontal flight in CRUISE.

GSF0.Y0 ... GSF0.Y4 show the yaw estimate from each of the 3-state EKF's. GSF0.YC is the composite yaw output from the Gaussian Sum Filter (GSF) which combines the yaw estimates from each 3-state EKF. For comparison the yaw estimate from the EKF3 is also shown. The GSF yaw starts to converge during the initial climb in QLOITER due to the small amount of horizontal motion and then rapidly finalises the convergence when the transition manouevre starts.

Screen Shot 2020-02-22 at 1 24 03 pm

Here are the weights calculated by the GSF and used to combine the individual yaw outputs from the 3-state EKF's. Also plotted is the estimated 1-Sigma yaw uncertainty for the GSF output in degrees.

Screen Shot 2020-02-22 at 1 23 56 pm

Here is the ground speed:

Screen Shot 2020-02-22 at 1 24 15 pm

The centripetal acceleration compensation using airspeed appears to be working effectively with the GSF yaw estimate closely tracking the EKF3 yaw through fixed wing flight.

Screen Shot 2020-02-22 at 1 45 55 pm

@priseborough
Copy link
Contributor Author

priseborough commented Feb 22, 2020

In addition to the flight test result presented above, another three flights with vertical takeoffs were performed with similar characteristics. The yaw partially converges during the vertical climb due to residual horizontal motion and rapidly completes convergence during transition to forward flight.

Takeoff 2
Screen Shot 2020-02-22 at 1 47 52 pm

Takeoff 3
Screen Shot 2020-02-22 at 1 50 20 pm

Takeoff 4
Screen Shot 2020-02-22 at 1 51 26 pm

@priseborough
Copy link
Contributor Author

SITL test results for patch b947374 which eliminates the use of quaternions. This change was inspired by the old DCM algorithm.

Weights:
image

Yaw Estimates:
image

@priseborough priseborough changed the title EKF3 Prototype Yaw Estimator Add yaw recovery that uses only IMU and GPS data Feb 27, 2020
@priseborough
Copy link
Contributor Author

@tridge I've moved it into a separate class but still need to add it to EKF2.

@priseborough
Copy link
Contributor Author

priseborough commented Feb 29, 2020

Todays testing performed using a quadplane in both RW and FW flight modes:

A total of 5 RW->FW transitions were performed across two flights. The first flight was with only 1 instance of EKF3 running using IMU1 (EK3_IMU_MASK = 1), the second flight used two instances (EK3_IMU_MASK = 3)

Flight 1: https://drive.google.com/open?id=19oji0tqwpPHhY5Uya-NxSKO_tK0TsDOq
Flight 2:https://drive.google.com/open?id=1q0Sdy4bzHKcOLdZwnT_G4uncnOwfI0RG

The following plots shows a vertical takeoff with transition into forward flight from flight 2:

EKF estimates:
Screen Shot 2020-02-29 at 2 13 06 pm

GSF Weights:
Screen Shot 2020-02-29 at 2 19 35 pm

As per previous testing there is enough horizontal motion during the vertical climb to enable the GSF to correctly estimate the yaw immediately after takeoff although reported uncertainty for the GSF yaw estimate stays around close to radians until forward transition enables the estimate to be improved.

Paul Riseborough added 11 commits March 1, 2020 14:41
Enable recovery from an EKF navigation failure caused by a bad yaw estimate.
Handle case where no airspeed sensor is fitted or airspeed data stops
Remove weighting function lower limit control.
Fix bug causing multiple alignments of each AHRS filter
Fixes a race condition that was causing the Copter EKF failsafe triggering after a successful reset.
Increases learned gyro bias saturation level from 3 to 5 deg/sec
Improve variable naming and consolidate GSF data into a struct.
Fix bug where AHRS gain was not updated if outside min/max accel.
Eliminate unnecessary conversions from accel to 'g'.
Enable the number of filters to be adjusted.
Enable the default airspeed used for centripetal acceleration compensation in fixed wing operation to be adjusted.
The propagation of the gyro delta angle and corrections is performed directly on the rotation matrix using a small angle approximation.
This is similar to the approach used by the AHRS legacy Dcm algorithm.
This has enabled the elimination of the quaternion states and a significant amount of unnecessary conversions between quaternions and other orientation descriptors.
@priseborough
Copy link
Contributor Author

I think it was probably just the EKF3 failing GPS innovation checks. When the GPS is reporting good accuracy, it only takes a few metres of movement for the 5-sigma consistency check to fail.

I assume you ended up placing the vehicle at the takeoff location before applying power.

@priseborough
Copy link
Contributor Author

SITL Copter flyaway test of commit 19edca7

Weights:
image

Yaw:
image

It is better to keep old weights.
The determinant calculation can handle a smaller determinant than previously allowed for.
@priseborough
Copy link
Contributor Author

Weights from test of b23f342

image

@priseborough
Copy link
Contributor Author

Thank you rmackay9 for posting the flight test video https://www.youtube.com/watch?v=3xW9hj-lxNU

@priseborough
Copy link
Contributor Author

I think we should consider adding the required IMU delay buffer into the yaw estimator and run a single yaw estimator on the first IMU instead of one per lane.

Comments other than this one have been addressed to the best of my knowledge. Moving this into a separate library with its own buffers for IMU and GPS is going to increase flash space unless we also move the IMU and GPs read and buffering into a template class to avoid another duplicate of the readGPSdata and readIMUdata functionality that is already replicated in EKF2 and EKF3. Doing this is beyond the time I have available for this task at this point in time and should be tackled in a separate PR.

Once this PR is in I can then then get the functionality into EKF2.

@priseborough
Copy link
Contributor Author

priseborough commented Mar 5, 2020

Testing at commit 6fc86ba using ArduPlane SITL used a takeoff with a 180 deg yaw error, tripping the yaw reset using the RC channel option and placing the vehicle into a loiter to monitor the centripetal accel correction. The airspeed sensor use was then stopped via the USE_ARSPEED parameter which forced the EKF to use the default value which is halfway between min and max param values. This resulted in a small increase in the velocity innovations for the 3-state filter banks, but yaw estimation remained acceptable.:

innovations

image

Edit: investigating the airspeed estimate received by the yaw estimator showed that there was a cm/s vs m/s error in ArduPlane.cpp where the default airspeed value was written. This has been fixed by 9e2abfa

See:

image

Paul Riseborough added 5 commits March 5, 2020 18:05
Removes unnecessary use of memcpy.
Documentation and code style fixes.
This better matches what current generation HW is able to support under typical flight conditions.
@priseborough
Copy link
Contributor Author

priseborough commented Mar 7, 2020

Today I was able to run multiple flight tests including the latest commits
ccd4490
and
f9d48b1 on a 250 size quad with COMPASS_AUTODEC = 0 and COMPASS_DEC = -1.59 (-90 deg).

Here is data from one of the flights - log here

Taking off in loiter mode, the EKF yaw reset 5m from the takeoff location and the fly-away arrested at 7m. The vehicle was recovered in RTL.

GPS ground track (yellow square is 10x10m)

Screen Shot 2020-03-07 at 6 37 23 pm

Here are the yaw estimates - note the EKF3 yaw (yellow line) resets to the GSF estimate at 17:55:51 when the GSF's reported yaw uncertainty drops below 15 degrees which is the exisiting threshold requirement for the EKF3 to use the GSF yaw estimate.

Screen Shot 2020-03-07 at 6 41 31 pm

Here are the GSF calculated weights for the individual yaw estimates:

Screen Shot 2020-03-07 at 6 41 50 pm

Here are the EKF3 GPS velocity innovations - note the immediate reduction in levels after the yaw reset at 17:55:51

Screen Shot 2020-03-07 at 6 44 37 pm

@priseborough
Copy link
Contributor Author

Here's the CPU and memory utilisation on the pixracer board with two EKF3 instances. Only the first EKF3 was running the GSF (EKF3_IMU_MASK = 3 and EK3_GSF_RUN = 1).

Screen Shot 2020-03-07 at 7 40 58 pm

@rmackay9
Copy link
Contributor

rmackay9 commented Mar 9, 2020

Note to self: remember to revert the changes to COMPASS_ORIENT before the next flight or your copter will come home in many pieces. :-)

@rmackay9
Copy link
Contributor

rmackay9 commented Mar 9, 2020

Two small things:

  • I'm not sure the PM.load is an accurate use of CPU but that's a side point
  • we should squash the commits to remove the "Revert:" commits

@priseborough
Copy link
Contributor Author

priseborough commented Mar 10, 2020

Have squashed commit history and continued here: #13776

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants